<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
        <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
        <title>Document</title>
        <style>
            div{padding: 50px}
            #div1{background-color: red}
            #div2{background-color: yellow}
            #div3{background-color: blue}
        </style>
        <script>
            window.onload = function(){
                var aDivs = document.getElementsByTagName("div");
                for(var i = 0; i < aDivs.length; i++){
                    aDivs[i].addEventListener("click", function(){
                        alert(this.id);
                    }, false);
                }
            }
        </script>
    </head>
    <body>
        <div id = 'div1'>
            <div id = 'div2'>
                <div id = 'div3'></div>
            </div>
        </div>
    </body>
</html>